<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
	<jsp:include page="/include.jsp"/>
	<script type="text/javascript">
	 $(document).ready(function(){
		 $("#btnQuery").bind("click",doQuery);
		 $("#btnReset").bind("click",doReset);
		 //加载用户角色数据
		 $('#framework_user_roleid').combobox({
				url:'${pageContext.request.contextPath}/systemManagerAction!getSelectRoleData.action',  
				valueField:'roleid',
				textField:'rolename',
				editable:false,
		 	 	onLoadSuccess:function(){
		 	 		//$('#framework_user_roleid').combobox('setValue',null);
				}
		 });
		 //加载所有部门数据
		 $('#framework_department_user_deptId').combotree({
			url:'${pageContext.request.contextPath}/systemManagerAction!getEtlDepartmentData.action?status=1',
			parentField : 'pid',
  			lines : true,
  			onSelect:function(data){
  				if(data.id!="parent"){
  					$("#framework_department_user_deptId").val(data.id);
  				}else{
  					$('#framework_department_user_deptId').combotree('clear');
  				}
  				
  			}
 	 	 });
		 
		 $('#framework_user_table').datagrid({
				url :'${pageContext.request.contextPath}/systemManagerAction!getAllUserInfo.action',
				fit:true,
				border:false,
				fitColumns:true,
				pagination:true,
				striped:true,
				pageList:[10,15,20],
				singleSelect:false,
				pagePosition:'bottom',
				autoRowHeight:true,
				rownumbers:false,
				sortName:'userid',
				columns:[[  {field:'userid',checkbox:true},
	 						{field:'username',title:'姓名',width:100,align:'left',sortable:true},
	 						{field:'rolename',title:'角色',width:120,align:'center'},
	 						{field:'deptName',title:'部门',width:120,align:'center'},
	 						{field:'phonenum',title:'手机号码',width:80,align:'right'},
	 						{field:'email',title:'电子邮箱',width:150,align:'right'},
	 						{field:'sex',title:'性别',width:30,align:'center',formatter:function(value,rowData,rowIndex){
	 							if(rowData.sex==1){
	 								return '男';
	 							}
	 							if(rowData.sex==2){
	 								return '女';
	 							}
	 						}},
	 						{field:'userdetailinfo',title:'自我简介',width:120,align:'left',formatter:function(value,rowData,rowIndex){
	 							if(rowData.userdetailinfo!=undefined){
	 								return '<div style="width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;" title="'+rowData.userdetailinfo+'">'+rowData.userdetailinfo+'</div>';
	 							}
	 						}},
	 						{field:'signatureinfo',title:'个性签名',width:120,align:'left',formatter:function(value,rowData,rowIndex){
	 							if(rowData.signatureinfo!=undefined){
	 								return '<div style="width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;" title="'+rowData.signatureinfo+'">'+rowData.signatureinfo+'</div>';
	 							}
	 						}},
	 						{field:'ww',title:'操作',width:100,align:'left',formatter:function(value,rowData,rowIndex){
	 							if(rowData.userid=="ADMIN"){
	 								return '<span  style="cursor:pointer;margin-right:15px;" onclick="doEdit(\''+rowData.userid+'\')"><img  src="${pageContext.request.contextPath}/images/icons/modify_or_edit.png" title="修改" alt="修改" style="margin-top:2px;"/>修改&nbsp;&nbsp;</span>'
	 								      +'<span  style="cursor:pointer;" >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>';
	 							}else{
								    return  '<span  style="cursor:pointer" onclick="doEdit(\''+rowData.userid+'\')"><img  src="${pageContext.request.contextPath}/images/icons/modify_or_edit.png" title="修改" alt="修改" style="margin-top:2px;"/>修改&nbsp;&nbsp;</span>'		
								           +'<span  style="cursor:pointer" onclick="doDelete(\''+rowData.userid+'\')"><img  src="${pageContext.request.contextPath}/images/icons/delete.png" title="删除" alt="删除" style="margin-top:2px;"/>删除&nbsp;&nbsp;</span>';
	 							}
	 							
	 						}}
	 					]],
				toolbar:'#framework_user_table_toobar'
			});
	 });
    function doReset(){
		$('#framework_user_username').val('');
		$('#framework_user_roleid').combobox('setValue','');
		$('#framework_user_select_sex').combobox('setValue','');
		$('#framework_department_user_deptId').combotree('clear');
	}
	//分页查询
	function doQuery()
	{
		var dataGridOptions=$('#framework_user_table').datagrid('options');
			dataGridOptions.queryParams=serializeObject($('#framework_user_table_form'));
			$('#framework_user_table').datagrid(dataGridOptions);
			$('#framework_user_table').datagrid('load');
	}
	
	//修改用户用户
	function doEdit(userid){
		window.top.$('<div/>').dialog({
			href:'${pageContext.request.contextPath}/systemManagerAction!executeModifyResult.action?userid='+userid,
			top:($(window.top).height()-400)*0.5,
		    left:($(window.top).width()-600)*0.5,
			width:530,
			modal:true,
			title:'修改用户',
			buttons:[{
				text : '保存',
				iconCls : '',
				handler:function(){
				    //获取用户性别参数
				    var usersex=window.top.$("input[type=radio][checked]").val();
					var d=window.top.$(this).closest('.window-body');
					if(window.top.$('#framework_modify_user_modify_form').form('validate'))
					{
						if(window.top.validateData()){
							window.top.$('#framework_modify_user_modify_form').form('submit',{
								url:'${pageContext.request.contextPath}/systemManagerAction!modifyUserInfo.action?sex='+usersex,
								success:function(result){
									try {
										var r=$.parseJSON(result);
										//显示提示信息
										$.messager.show({
											title:'提示',
											msg:r.returnMsg
										});
										//关闭新增窗口
										d.dialog('destroy'); 
										//刷新主列表
										$('#framework_user_table').datagrid('reload');	
									} catch (e) {
										$.messager.alert('提示', result);
									}
								}
							});
						}
					}
				}
			}],
			onClose:function(){
				window.top.$(this).dialog('destroy');
			}
		});
	}
	//新增用户用户
	function doAdd(){
		window.top.$('<div/>').dialog({
			href:'${pageContext.request.contextPath}/framework/systemManager/user/user_manager_newuser.jsp',
			top:($(window.top).height()-400)*0.5,
		    left:($(window.top).width()-600)*0.5,
			width:530,
			modal:true,
			title:'新增用户',
			buttons:[{
				text : '保存',
				iconCls : '',
				handler:function(){
				    //获取用户性别参数
				    var usersex=window.top.$("input[type=radio][checked]").val();
					var d=window.top.$(this).closest('.window-body');
					if(window.top.validateData()){
						window.top.$('#framework_user_addform').form('submit',{
							url:'${pageContext.request.contextPath}/systemManagerAction!addUserInfo.action?sex='+usersex,
							success:function(result){
								try {
									var r=$.parseJSON(result);
									//显示提示信息
									$.messager.show({
										title:'提示',
										msg:r.returnMsg
									});
									//关闭新增窗口
									d.dialog('destroy'); 
									//刷新主列表
									$('#framework_user_table').datagrid('reload');	
								} catch (e) {
									window.top.$.messager.alert('提示', result);
								}
							}
						});
					}
				}
			}],
			onClose:function(){
				window.top.$(this).dialog('destroy');
			}
		});
	}
	//单独删除
	function doDelete(userid){
		$.messager.confirm('删除确认', '确定要删除该条记录吗？',function(r){
			if(r){
				$('#framework_user_table_form').form('submit',{
					url:'${pageContext.request.contextPath}/systemManagerAction!deleteBatchUser.action?batchFlag=false&pid='+userid,
				    success:function(result){
					   try {
							var r = $.parseJSON(result);
							$.messager.show({
								title : '提示',
								msg : r.returnMsg
							});
							if (r.returnFlag) {
								$('#framework_user_table').datagrid('reload');
							}
						} catch (e) {
							$.messager.alert('提示', result);
						}
				    } 
		       });
			}
		});
	}
	
	//批量删除
	function doBatchDelete()
	{
		var rows=$('#framework_user_table').datagrid('getChecked')
		if(rows.length<=0){
			$.messager.alert('提示','没有选择任何记录');
		}else{
			for(var idx=0;idx<rows.length;idx++){
				if(rows[idx].userid=="ADMIN"){
					$.messager.alert("操作提示","管理员不允许被删除!");
					return;
				}
			}
			$.messager.confirm('删除确认', '确定要删除所选择的记录吗？', function(r){
				if (r){
						$('#framework_user_table_form').form('submit',{
						url:'${pageContext.request.contextPath}/systemManagerAction!deleteBatchUser.action?batchFlag=true',
						success:function(result){
							try {
								var r = $.parseJSON(result);
								$.messager.show({
									title : '提示',
									msg : r.returnMsg
								});
								if (r.returnFlag) {
									$('#framework_user_table').datagrid('reload');
								}
							} catch (e) {
								$.messager.alert('提示', result);
							}
						}
					});
				}
			});
		}
	}
	</script>
</head>
<body class="easyui-layout">
    <form id="framework_user_table_form" method="post">
        <div data-options="region:'north'" style="height:80px;border-bottom:none;border-top:none;">
	    	<table border="0" cellpadding="0" cellspacing="0" height="100%"  width="100%" >
	    		<tr>
		    		<td style="text-align:right;width:10%;" nowrap="nowrap">
		    			<label>用户名称：&nbsp;</label>
		    		</td>
					<td style="text-align:left;width:15%;" >
	    				<input type="text" id="framework_user_username" name="username"/>
					</td>
					<td style="text-align:right;width:10%;" nowrap="nowrap">
						<label>用户角色：&nbsp;</label>
					</td>
					<td style="text-align:left;width:15%;" >
	    				<input type="text" id="framework_user_roleid" name="roleid" panelHeight="auto"/>
					</td>
					<td style="text-align:right;width:10%;"  nowrap="nowrap">
						<label>用户部门：&nbsp;</label>
					</td>
					<td style="text-align:left;width:15%;" >
	    				<input type="text" id="framework_department_user_deptId" name="deptId" />
					</td>
					<td style="text-align:right;width:10%;"  nowrap="nowrap">
						<label>用户性别：&nbsp;</label>
					</td>
					<td style="text-align:left;width:15%;padding-right:35px" >
	    				<select  id="framework_user_select_sex" name="sex" class="easyui-combobox" data-options="editable:false" panelHeight='auto'  style="width:180px;">
							<option value="">全部</option>
							<option value="1">男</option>
							<option value="2">女</option>
						</select>
					</td>
	    		</tr>
	    		<tr>
		    		<td style="text-align:right;width:10%;" >
		    		</td>
					<td style="text-align:left;width:15%;" >
					</td>
					<td style="text-align:right;width:10%;" >
					</td>
					<td style="text-align:left;width:15%;" >
					</td>
					<td style="text-align:right;width:10%;" >
					</td>
					<td style="text-align:left;width:15%;" >
					</td>
					<td colspan="2" style="width:25%;text-align:right;" nowrap="nowrap" >	   
			    		<input type="button" id="btnQuery" name="" value="查 询" style="cursor:pointer;background-image: url('${pageContext.request.contextPath}/images/login/search.png');background-repeat: no-repeat;width:67px;height:23px;padding-left:12px;border:none;color:white;font-family:微软雅黑;"/>	
			    		<input type="button" id="btnReset" name="" value="重 置" style="cursor:pointer;background-image: url('${pageContext.request.contextPath}/images/login/reset.png');background-repeat: no-repeat;width:67px;height:23px;padding-left:12px;border:none;color:white;font-family:微软雅黑;margin-right:35px"/>				
	    			</td>
	    		</tr>
			</table>
	    </div>  
		<div data-options="region:'center'" style="border-top:none">
			<table id="framework_user_table"></table>
			<div id="framework_user_table_toobar" class="etl_panel_title" >
				<a href="javascript:void(0);" onclick="doAdd()" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" style="float:left;">新增用户</a>
				<div class="datagrid-btn-separator"></div>
				<a href="javascript:void(0);" onclick="doBatchDelete()" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true">批量删除</a>
			</div>
		</div>
    </form>
</body>
</html>
